package app.models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @author Marcos V. Aguiar
 * @since 26/12/2013
 */

@Entity
@Table(name = "CH")
public class CH implements Pojo {

	private static final long serialVersionUID = -1735190518839351663L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	private Long id;
	
	@NotNull(message = "{valor.empty}")
	@Column(name = "VALOR", columnDefinition = "double")
	private Double valor;
	
	@Min(value = 1, message = "{convenio.empty}")
	@Column(name = "ID_CONVENIO")
	private Integer idConvenio;
	
	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "ID_CONVENIO", referencedColumnName = "ID", insertable = false, updatable = false)
	private Convenio convenio;
	
	@Transient
	private String valorString;
	
	public Long getId() {
		return this.id;
	}
	
	public Integer getIdConvenio() {
		return idConvenio;
	}

	public String getValorString() {
		return valorString;
	}

	public void setValorString(String valorString) {
		this.valorString = valorString;
	}

	public void setIdConvenio(Integer idConvenio) {
		this.idConvenio = idConvenio;
	}

	public Convenio getConvenio() {
		return convenio;
	}

	public void setConvenio(Convenio convenio) {
		this.convenio = convenio;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Double getValor() {
		return valor;
	}

	public void setValor(Double valor) {
		this.valor = valor;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CH other = (CH) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
}
